const {Sequelize, DataTypes} = require("sequelize");
const start = require("./utils/connect");

(async()=>{
  const sequelize = await start();
  const User = sequelize.define("User",{
    firstName:{
      type:DataTypes.STRING,
      allowNull:false
    },
    lastName:{
      type:DataTypes.STRING
    }
  },{
    paranoid:true,
    freezeTableName:true // 强制使用定义表名
  });


  await sequelize.sync({
    force:true
  });

  console.log("模型同步成功");


  try {

    let result = await sequelize.transaction(async t=>{
      const user = await User.create({
        firstName:"hao",
        lastName:"wu"
      },{transaction:t});
      return user;
    });
    
    console.log(result.toJSON());
    
  } catch (error) {
    
  }

  


})()